<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../ht-css/Project.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js?rev=@@hash"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css"/>
    <link rel="stylesheet" href="../../ht-css/combo.select.css">
    <title >所属分类</title>
</head>
<body>
<article class="page-container">
    <form class="ml-20 mr-20" id="form-member-add" method="post">
        <div>
            <div class="pd-5 bg-1 bk-gray pb-10">
                <div class="lh-30 pd-10">
                    <table class="table-hover table_li ml-10 mb-10 table">
                        <thead class="text-l">
                        <tr>
                            <td>
                                <div class="formControls">
                                    <input type="text" autocomplete="off" class="input-text radius" name="class1" placeholder="请选择一级分类"
                                           oninput="goods_listCategory(1)" id="class1">
                                    <ul class="relation radius guanlian" id="classUl1">
                                    </ul>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="formControls">
                                    <input type="text" autocomplete="off" class="input-text radius" name="class2" placeholder="请选择二级分类"
                                           id="class2">
                                    <ul class="relation radius guanlian" id="classUl2">
                                    </ul>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="formControls">
                                    <input type="text" autocomplete="off" class="input-text radius" name="class3" placeholder="请选择三级分类"
                                           id="class3">
                                    <ul class="relation radius guanlian" id="classUl3">
                                    </ul>
                                </div>
                            </td>
                        </tr>
                        </thead>
                    </table>
                    <div class="row cl">
                        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                            <button type="submit" onclick="saveClass()" class="btn btn-primary radius subSure">&nbsp;&nbsp;确认&nbsp;&nbsp;</button>
                            <button onclick="removeIframe()" class="btn btn-default radius ml-10" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</article>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui/js/H-ui.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui.admin/js/H-ui.admin.js?rev=@@hash"></script> <!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script type="text/javascript" src="../../ht-js/frame/doT.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.combo.select.js?rev=@@hash"></script>
<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
<script src="../../ht-js/Project.js?rev=@@hash"></script>
<script>
    /*取消*/
    function removeIframe() {
        var index = parent.location.reload();
        parent.layer.close(index);
    }
    function saveClass() {
        var categoryNameArr = {
            class1:$("#class1").val(),
            class2:$("#class2").val(),
            class3:$("#class3").val(),
        };
        sessionStorage.setItem("categoryNameArr", JSON.stringify(categoryNameArr));
        var index = parent.location.reload();
        parent.layer.close(index);
    }
    function goods_listCategory(categoryLevel) {
        var categoryName = $("#class1").val();
        var user_data = {
            categoryLevel: categoryLevel,
            categoryName: $("#class1").val(),
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if (data.errorCode == "0") {
                if (data.data == null) {
                    classStr = "<li>无数据</li>"
                    $("#classUl1").html(classStr);
                } else {
                    var classStr = "";
                    for (var i = 0; i < data.data.length; i++) {
                        classStr += "<li onclick='nextClass(" + data.data[i].category_id + "," + data.data[i].category_level + ",\"" + data.data[i].category_name + "\")'>" + data.data[i].category_name + "</li>"
                    }
                    $("#classUl1").html(classStr);
                }
            }
        }
        web.doAjax(root.goodsInter.categoryByParam, 'post', user_data, succCallBack);
    }

    //获取光标
    $("#class1").focus(function () {
        $("#classUl1").show();
        goods_listCategory(1);
    });
    $(document).bind("click", function (e) {
//id为menu的是菜单，id为open的是打开菜单的按钮
        if ($(e.target).closest("#classUl1").length == 0 && $(e.target).closest("#class1").length == 0) {
//点击id为menu之外且id不是不是open，则触发
            $("#classUl1").hide()
        }
    });

    // 2,3,4级的模糊查询
    function getNext_input(level, category_id) {
        console.log(level)
        if (level<4){
            $("#class" + level + "")[0].oninput = function () {
                console.log(111)
                goods_listCategory(level, level, category_id);
            }
//获取光标
            $("#class" + level + "").focus(function () {
                $("#classUl" + level + "").show();
                goods_listCategory(level, level, category_id);
            });
            $(document).bind("click", function (e) {
//id为menu的是菜单，id为open的是打开菜单的按钮
                if ($(e.target).closest("#classUl" + level + "").length == 0 && $(e.target).closest("#class" + level + "").length == 0) {
//点击id为menu之外且id不是不是open，则触发
                    $("#classUl" + level + "").hide()
                }
            });
        }

    }

    function nextClass(category_id, level, category_name) {
        $("#class" + level + "").val(category_name)
        if(level == 1){
            $("#class2").val("");
            $("#class3").val("");
        }else if(level == 2){
            $("#class3").val("");
        }
        var user_data = {
            parentCateId: category_id
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if (data.errorCode == "0") {
                if (data.data == null) {
                    classStr = "<li>无数据</li>";
                } else {
                    var classStr = "";
                    for (var i = 0; i < data.data.length; i++) {
                        classStr += "<li onclick='nextClass(" + data.data[i].category_id + "," + data.data[i].category_level + ",\"" + data.data[i].category_name + "\")'>" + data.data[i].category_name + "</li>"
                    }
                }
                if(data.data[0] == undefined){
                    classValue = category_id;
                    var nextLevel = level+1;
                    $("#classUl" + nextLevel + "").html(classStr);
                    $("#classUl" + level + "").hide();
                }else {
                    var nextLevel = data.data[0].category_level;
                    $("#classUl" + nextLevel + "").html(classStr);
                    $("#classUl" + nextLevel + "").show();
                    $("#classUl" + level + "").hide()
                }
            }
        }
        getNext_input(level + 1, category_id);
        web.doAjax(root.goodsInter.categoryByParam, 'post', user_data, succCallBack);
    }
</script>
</body>
</html>